package com.learn.factory;

import java.util.HashMap;
import java.util.Map;

public class ProductFactory {
    private static final Map<String, Product> productMap = new HashMap<>();

    public static synchronized Product createProduct(String type) {
        Product product;

        // 如果有容器的话，就直接返回
        if (productMap.containsKey(type)) {
            product = productMap.get(type);
        } else {
            // 否则创建了以后再返回
            product = new Product();
            productMap.put(type, product);
        }

        return product;
    }
}
